import React, { Component } from 'react'
import MyContext from './MyContext'
import Child from './Child'

export default class Parent extends Component {

  constructor() {
    super()
    this.state = {
      city: '太原'
    }
  }

  //contextType 名字，约定的写法
  static contextType = MyContext;

  render() {
    return (
      //定义了value之后，MyContext 提供的默认数据就失效了
      <MyContext.Provider value={{
        city:this.state.city
      }}>
        <div>
          parent:{
            this.context.name
          }
          <Child></Child>
        </div>
      </MyContext.Provider>
    )
  }

  componentDidMount() {
    console.log(this.context)
  }

}
